@extends('admin.layouts.ui')
@section('title','后台管理欢迎页面')
@section('content')
<!-- 模态框（Modal） -->
<div class="row">
    <div class="card">
        <div class="card-body">
            {!! Form::model($carousel,['route' => ['advertising.update',$carousel->id], 'method' => 'PATCH','id' =>'form']) !!}
            <div class="form-row">

                <div class="form-group col-lg-6">
                    <label for="firstname">图片标题</label>
                    <input type="text" value="{{ $carousel->title }}" name="title" class="form-control" id="firstname">
                </div>
                <div class="form-group col-lg-6">
                    <label for="lastname">标题</label>
                    <input type="text" class="form-control" id="sort" name="sort" value="{{ $carousel->sort }}">
                </div>
                <div class="form-group col-lg-6">
                    <label for="lastname">排序</label>
                    <input type="text" class="form-control" id="sort" name="sort" value="{{ $carousel->sort }}">
                </div>
                <div class="form-check col-md-12 m-b-20">
                    @if ($carousel->is_show == '显示')
                        <div class="custom-control custom-radio radio custom-control-inline">
                            <input type="radio" class="custom-control-input" name="is_show" value="0" id="is_show" checked="checked">
                            <label class="custom-control-label" for="is_show">显示</label>
                        </div>
                        <div class="custom-control custom-radio radio custom-control-inline">
                            <input type="radio" class="custom-control-input" name="is_show" value="1" id="gender">
                            <label class="custom-control-label" for="gender">隐藏</label>
                        </div>
                    @else
                        <div class="custom-control custom-radio radio custom-control-inline">
                            <input type="radio" class="custom-control-input" name="is_show" value="0" id="is_show">
                            <label class="custom-control-label" for="is_show">显示</label>
                        </div>
                        <div class="custom-control custom-radio radio custom-control-inline">
                            <input type="radio" class="custom-control-input" name="is_show" value="1" id="gender" checked="checked">
                            <label class="custom-control-label" for="gender">隐藏</label>
                        </div>
                    @endif
                </div>
                <div class="form-group col-lg-12">
                    <label for="username">图片上传</label>
                    <div class="card">
                        <div class="card-body">
                            <h3 class="card-title">留空则不修改</h3>
                            <blockquote class="card-bodyquote">
                                <div id="cupload-create" style="padding: 10px;"></div>

                            </blockquote>
                        </div>
                    </div>
                </div>
                <div class="form-group col-lg-12 text-righ">
                    <button type="submit" class="btn btn-common ml-5">修改</button>
                </div>
            </div>
            {!! Form::close() !!}
        </div>
    </div>
</div>
@stop
@section('js')
    <script src="{{ asset('admin/Widget/cupload/cupload.js') }}"></script>
    <script type="text/javascript">
        var cuploadCreate = new Cupload({
            ele: '#cupload-create',
            num: 1,
        });
        $('#form').Validform({
            tiptype : 4,
            ajaxPost : true,
            beforeCheck:function(curform){
                console.log(curform);
                //在表单提交执行验证之前执行的函数，curform参数是当前表单对象。
                //这里明确return false的话将不会继续执行验证操作;
                index = layer.load(1, {shade: [0.6, '#393D49']});
            },
            callback : function (res) {
                console.log(res);
                if(res.status == 422) {
                    var json=JSON.parse(res.responseText);
                    $.each(json.errors, function(idx, obj) {
                        layer.msg(obj[0], {icon: 5});
                        layer.close(index);
                        return false;
                    });
                } else if(res.status== 200) {
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.href = '{{ route('advertising.index') }}'
                    });

                }
            },
        });
    </script>
@stop
